package com.isoft.mapper;

import com.isoft.entity.DfmeDlyeEntity;
import org.apache.ibatis.annotations.*;

@Mapper
public interface DfmeDlyeMapper {

    @Insert("INSERT INTO MSG_META(SENDER, RECEIVER, SEQUENCE_NUMBER, DATE_TIME, MSG_TYPE, SUB_TYPE) " +
            "VALUES(" +
            "#{meta.sender,jdbcType=VARCHAR}, " +
            "#{meta.receiver,jdbcType=VARCHAR}, " +
            "#{meta.sequenceNumber,jdbcType=NUMERIC}, " +
            "TO_TIMESTAMP(#{meta.dateTime,jdbcType=VARCHAR}, 'yyyymmddhh24miss'), " +
            "#{meta.type,jdbcType=VARCHAR}, " +
            "#{meta.subType,jdbcType=VARCHAR})")
    @Options(useGeneratedKeys = true, keyProperty = "msgId", keyColumn = "MSG_ID")
    void insertMeta(DfmeDlyeEntity entity);

    @Insert("INSERT INTO FLIGHT_BASE(" +
            "FLIGHT_ID, FLIGHT_ATTRIBUTE, FLIGHT_FILE_ID, FLIGHT_IDENTIFIER, STATUS, AIRPORT_CODE) " +
            "VALUES(" +
            "#{dflt.flightId,jdbcType=NUMERIC}, " +
            "#{dflt.flightAttribute,jdbcType=VARCHAR}, " +
            "#{dflt.flightFileId,jdbcType=VARCHAR}, " +
            "#{dflt.flightIdentifier,jdbcType=VARCHAR}, " +
            "'DELAYED', " +
            "'PEK')")  // 使用有效的机场代码
    int insertFlightBase(DfmeDlyeEntity entity);

    @Insert("INSERT INTO FLIGHT_IRREGULARITY(" +
            "FLIGHT_ID, ABNORMAL_STATUS, ABNORMAL_REASON, " +
            "INTERNAL_STATUS, INTERNAL_REASON, MANUAL_ABNORMAL_STATUS, " +
            "MANUAL_ABNORMAL_REASON, MANUAL_INTERNAL_STATUS, MANUAL_INTERNAL_REASON) " +
            "VALUES(" +
            "#{dflt.flightId,jdbcType=NUMERIC}, " +
            "#{dflt.abnormalStatus,jdbcType=VARCHAR}, " +
            "#{dflt.abnormalReason,jdbcType=VARCHAR}, " +
            "#{dflt.internalStatus,jdbcType=VARCHAR}, " +
            "#{dflt.internalReason,jdbcType=VARCHAR}, " +
            "COALESCE(#{dflt.manualAbnormalStatus,jdbcType=VARCHAR}, NULL), " +
            "COALESCE(#{dflt.manualAbnormalReason,jdbcType=VARCHAR}, NULL), " +
            "COALESCE(#{dflt.manualInternalStatus,jdbcType=VARCHAR}, NULL), " +
            "COALESCE(#{dflt.manualInternalReason,jdbcType=VARCHAR}, NULL))")
    int insertFlightIrregularity(DfmeDlyeEntity entity);

    @Insert("INSERT INTO FLIGHT_ROUTE(" +
            "FLIGHT_ID, AIRPORT_CODE, AIRPORT_SEQ, ESTIMATED_TIME) " +
            "VALUES(" +
            "#{dflt.flightId,jdbcType=NUMERIC}, " +
            "'PEK', " +
            "1, " +
            "TO_TIMESTAMP(#{dflt.estimatedTime,jdbcType=VARCHAR}, 'yyyymmddhh24miss'))")
    int insertFlightRoute(DfmeDlyeEntity entity);
}